package cn.smilefox.controller;


import cn.smilefox.domain.Course;
import cn.smilefox.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RequestMapping("/courses")
@Controller
public class CourseController {

    @Autowired
    private CourseService courseService;

    //查询所有试验课程信息展示
    @RequestMapping("testlist")
    public ModelAndView findalltest(){

        ModelAndView modelAndView = new ModelAndView();
        List<Course> courseList = courseService.findalltest();

        //设置模型
        modelAndView.addObject("courseList",courseList);
        //设置视图
        modelAndView.setViewName("testcourses-list");

        return modelAndView;
    };

    //添加试验课程
    @RequestMapping("testsave")
    public String testsave(Course course){

        courseService.save(course);

        return "redirect:/courses/testlist";
    };

    //删除实验课程
    @RequestMapping("/testdel/{courseid}")
    public String testdel(@PathVariable("courseid") Long courseid){

        courseService.testdel(courseid);
        return "redirect:/courses/testlist";
    };

    //查询实验课程
    @RequestMapping("/findtest")
    public ModelAndView modelAndView(Course course){
        ModelAndView modelAndView = new ModelAndView();

        List<Course> courseList = courseService.findtest(course);
        modelAndView.addObject("courseList",courseList);
        modelAndView.setViewName("testcourses-list");
        return modelAndView;
    };



    //---------------------- 理论课程 ----------------------------------


    //查询所有理论课程信息展示
    @RequestMapping("theorylist")
    public ModelAndView findalltheory(){

        ModelAndView modelAndView = new ModelAndView();
        List<Course> courseList = courseService.findalltheory();

        //设置模型
        modelAndView.addObject("courseList",courseList);
        //设置视图
        modelAndView.setViewName("theorycourses-list");

        return modelAndView;
    };

    //添加试验课程
    @RequestMapping("theorysave")
    public String theorysave(Course course){

        courseService.savetheory(course);

        return "redirect:/courses/theorylist";
    };

    //删除理论课程
    @RequestMapping("/theorydel/{courseid}")
    public String theorydel(@PathVariable("courseid") Long courseid){

        courseService.theorydel(courseid);
        return "redirect:/courses/theorylist";
    };

    //查询实验课程
    @RequestMapping("/findtheory")
    public ModelAndView modelAndView1(Course course){
        ModelAndView modelAndView = new ModelAndView();
        List<Course> courseList = courseService.findtheory(course);
        modelAndView.addObject("courseList",courseList);
        modelAndView.setViewName("theorycourses-list");
        return modelAndView;
    };

    //-------------------课程工作量核算统计-----------------
    @RequestMapping("/coursenum")
    public ModelAndView modelAndViewnum(){
        ModelAndView modelAndView = new ModelAndView();
        List<Course> courseList = courseService.findallnum();
        modelAndView.addObject("courseList",courseList);
        modelAndView.setViewName("coursesnum-list");
        return modelAndView;
    };

}
